package view.itemRenderes.mediators
{
	import events.library.EventSetLibraryItemProperty;
	
	import flash.events.Event;
	
	import model.ModelLibrary;
	
	import mx.controls.Alert;
	
	import org.flashIso.engine.library.objects.LBase;
	import org.robotlegs.mvcs.Mediator;
	
	import view.itemRenderes.ItemRendererLbinaryData;
	
	
	public class MediatorItemRendererLBinaryData extends Mediator
	{
		[Inject]
		public var v:ItemRendererLbinaryData;
		
		[Inject]
		public var ml:ModelLibrary;
		
		override public function onRegister() : void  {
			eventMap.mapListener(v, Event.CHANGE, labelChange, Event);
		}
		
		private function labelChange(e:Event) : void {
			if (ml.getLBinaryDataByID(v.textInput.text) != null){
				Alert.show("A binary with this id already exists!","Rename Binary");
			}else{
				dispatch(new EventSetLibraryItemProperty(EventSetLibraryItemProperty.CHANGE_LIBRARY_ITEM_PROPERTY, v.data as LBase, "id", v.textInput.text));
			}
			
		}
	}
}